
import { BASEURL } from 'constants';

function request({ url, method="GET", params={}, header }) {
  url = BASEURL + url;
  return new Promise((resolve, reject) => {
    wx.request({
      url,
      header: {'content-type': 'application/json; charset=utf-8', ...header},
      method,
      data: params,
      timeout: 5000,
      success(res) {
        resolve({...res.data, cookies: res.cookies});
      },
      fail(err) {
        reject(err);
      },
      complete() {}
    });
  });
}

export {
  request
}